#!/bin/bash

updatequotes() {
uri=$(curl -s "https://api.quotable.io/random?maxLength=110")

echo $uri | jq '.content' |  cut -d "\"" -f 2 > "$HOME/.cache/eww.quote"
echo $uri | jq '.author' |  cut -d "\"" -f 2 > "$HOME/.cache/eww.author"
}

quote=$(cat $HOME/.cache/eww.quote)
author=$(cat $HOME/.cache/eww.author)

if [ "$quote" = "" ] ; then
	  quote="Bad programmers worry about the code. Good programmers worry about data structures and their relationships."
    author="Linus Torvalds"
fi

case $1 in
quote)
echo $quote
;;
author)
echo "~ $author ~"
;;
update)
  updatequotes
;;
esac
